// pages/couponmanagebox/couponlist/couponlist.js
import {
  getCoupons,
  sendCoupon
} from '../../../utils/networkRequest.js';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    coupons: null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onShow: function() {
    let self = this;
    getCoupons((r) => {
      debugger;
      self.setData({
        coupons: r.data
      })
    })
  },
  //添加优惠券
  goAddCouPon: function() {
    wx.navigateTo({
      url: '../couponmanage/couponmanage',
    })
  },
  //编辑优惠券
  // editCoupon: function(e) {
  //   let item = e.currentTarget.dataset.item;
  //   wx.navigateTo({
  //     url: '../couponmanage/couponmanage?isEdit=true&item=' + JSON.stringify(item),
  //   })
  // },
  //发送优惠券
  onSend: function(e) {
    let coupon_id = e.currentTarget.dataset.couponid 
    wx.showModal({
      title: '提示',
      content: '确定要向所有车主发送此优惠券吗？',
      success: function (res) {
        if (res.confirm) {
        
          sendCoupon(coupon_id, (r) => {
            if (r.code == 0) {
              wx.showToast({
                icon: 'none',
                title: '发送成功',
              })
            }
          })
        } else if (res.cancel) {
          //点击取消
        }
      }
    })


    
    
  }
})